package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) {
        try {
            // 正确加载 MySQL 驱动类
            Class.forName("com.mysql.cj.jdbc.Driver");
            // 建立数据库连接
            String url = "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true";
            String username = "root";
            String password = "ROOT";

            Connection conn = DriverManager.getConnection(url, username, password);

            // 输出连接成功信息
            System.out.println("数据库连接成功！");

            Statement statement = conn.createStatement();
            String sql="UPDATE user " +
                    "SET name='李四',phone='13243546578' " +
                    "WHERE id=1";
            int rows =statement.executeUpdate(sql);
            if (rows > 0) {
                System.out.println("更新成功！");
            }else {
                System.out.println("更新失败！");
            }
            statement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
